package controllers;

import java.util.List;

import play.mvc.Controller;
import play.mvc.Controller;
import play.mvc.Http;
import play.mvc.With;
import models.Comment;
import models.Event;
import models.User;
@Check("Administrator")
@With(MySecure.class)
public class AdministrationManager extends Controller {
	

	public static void delete(long eventID)
	{
		Event event = Event.findById(eventID);
		event.delete();
		manage();
	}
	public static void deleteComment(long commentID,long eventID)
	{
		Comment comment = Comment.findById(commentID);
		comment.delete();
		detailedeventAdmin(eventID);
	}
	public static void manage()
	{
		List<Event> events = Event.findAll();
		render(events);

	}
	public static void detailedeventAdmin(Long id) {
		Event event = Event.findById(id);
		render(event);
	}
	public static void postCommentAdmin(Long eventId, String content) {
		Event event = Event.findById(eventId);
		User user = User.find("byEmail", session.get("username")).first();
		if(user==null) {
			UserManager.index();
		}
		else {
			event.addComment(user, content);
			detailedeventAdmin(eventId);
		}
	}
	
}
